package com.awakensoftware.hunterserver.serverentities;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;

@Entity
@Table(name = "Treasures")
public class Treasure extends ServerEntityBase {

	private static final long serialVersionUID = 354249923666547813L;

	// Database fields and relationships
	@Id
	@GeneratedValue
	@Column(name = "id")
	private long id;

	@Column(length = 256, unique = false, name = "name")
	private String name;
	
	@Column(length = 1000, unique = false, name = "treasure_message")
	private String treasureMessage;

	@OneToOne(mappedBy = "treasureInstance")
	private TreasureTemplate treasureTemplate;

	@ManyToOne
	@JoinColumn(name = "chest_id", referencedColumnName = "id")
	private Chest chest;

	@Override
	public void setName(String name) {
		this.name = name;
	}

	@Override
	public String getName() {
		return name;
	}

	@Override
	public long getId() {
		return id;
	}

	@Override
	public void setId(long id) {
		this.id = id;
	}

	public TreasureTemplate getTreasureTemplate() {
		return this.treasureTemplate;
	}

	public void setTreasureTemplate(TreasureTemplate treasureTemplate) {
		this.treasureTemplate = treasureTemplate;
	}

	public void setChest(Chest chest) {
		this.chest = chest;
	}

	public Chest getChest() {
		return this.chest;
	}

	public String getTreasureMessage() {
		return treasureMessage;
	}

	public void setTreasureMessage(String treasureMessage) {
		this.treasureMessage = treasureMessage;
	}

	public boolean validate() {
		if (name == null || name.trim().length() == 0) {
			return false;
		}
		return true;
	}

}
